package com.extremelylargepackage.entity;

import android.util.Log;

import com.extremelylargepackage.GameResources;

public class AiKamikaze implements AiMoveComponent
{
	private Enemy _me;

	private boolean _movingTarget;
	private boolean _linear;
	
	private boolean _targetSet;
	private boolean _finished;
	
	public AiKamikaze(boolean seek, boolean linear)
	{
		_movingTarget = seek;
		_linear = linear;
	}
	
	@Override
	public void performMove(long time)
	{
		if(_linear && !_targetSet) {
			_me._dirY = GameResources.SCREEN_HEIGHT - _me._locY;
			_targetSet = true;
		}
		else if(_movingTarget || !_targetSet && _me._locY < _me._player._locY + _me._player.getHeight()) {
			//Scale dirX and dirY 
			_me._dirY = GameResources.SCREEN_HEIGHT - _me._locY;
			float scale = _me._dirY / (_me._player._locY - _me._locY);
			_me._dirX = (_me._player._locX - _me._locX) * scale;
			_targetSet = true;
		}
		
		if((_me._dirX  == 0 && _me._dirY == 0) || _me._locY > GameResources.SCREEN_HEIGHT)
		{
			_finished = true;
		}
	}

	@Override
	public void setSelf(Enemy me)
	{
		_me = me;
	}
	
	public Object clone()
	{
		return new AiKamikaze(_movingTarget, _linear);	
	}

	@Override
	public boolean finished() 
	{
		return _finished;
	}
}
